package com.ztl.onestopinterfacebackend.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ztl.onestopinterfacebackend.exception.ErrorCode;
import com.ztl.onestopinterfacebackend.exception.ThrowUtils;
import com.ztl.onestopinterfacebackend.model.entity.InterfaceInfo;
import com.ztl.onestopinterfacebackend.service.InterfaceInfoService;
import com.ztl.onestopinterfacebackend.mapper.InterfaceInfoMapper;
import org.springframework.stereotype.Service;

/**
* @author Canway
* @description 针对表【interface_info(接口信息)】的数据库操作Service实现
* @createDate 2025-09-09 11:12:41
*/
@Service
public class InterfaceInfoServiceImpl extends ServiceImpl<InterfaceInfoMapper, InterfaceInfo>
    implements InterfaceInfoService{

    @Override
    public void validInterfaceInfo(InterfaceInfo interfaceInfo, boolean add) {
        // 校验
        ThrowUtils.throwIf(interfaceInfo.getId() == null, ErrorCode.PARAMS_ERROR, "id不能为空");
        String name = interfaceInfo.getName();
        // 创建时，所有参数必须非空
        if (add) {
            ThrowUtils.throwIf(StrUtil.isAllBlank(name), ErrorCode.PARAMS_ERROR, "名称不能为空");
        }
        ThrowUtils.throwIf(StrUtil.isBlank(name) && name.length() > 50, ErrorCode.PARAMS_ERROR, "名称过长");
    }

}




